package com.lambda.use;

/**
 * 功能描述
 *
 * @author: jichao.huang
 * @date: 2025年06月04日 17:43
 */
@FunctionalInterface
interface PaymentStrategy {
    void pay(double amount);
}

class ShoppingCart {
    private PaymentStrategy paymentStrategy;

    public void setPaymentStrategy(PaymentStrategy strategy) {
        this.paymentStrategy = strategy;
    }

    public void checkout(double amount) {
        paymentStrategy.pay(amount);
    }
}

public class StrategyExample {
    public static void main(String[] args) {
        ShoppingCart cart = new ShoppingCart();

        // 设置信用卡支付策略
        cart.setPaymentStrategy(amount ->
                System.out.println("使用信用卡支付: $" + amount));
        cart.checkout(100.0);

        // 设置支付宝支付策略
        cart.setPaymentStrategy(amount ->
                System.out.println("使用支付宝支付: ￥" + amount*7));
        cart.checkout(100.0);
    }
}
